/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ec.socialfun.convertidores;

import com.ec.socialfun.entidades.Evento;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import org.jboss.logging.Logger;

/**
 *
 * @author hp
 */

@FacesConverter("eventoConvertidor")
public class EventoConvertidor implements Converter{

    private static final Logger LOG = Logger.getLogger(EventoConvertidor.class.getName());
    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String valor) {
        try{
            LOG.info("Convertidor1 -------------- "+valor);
            return new Evento(Integer.parseInt(valor));
        }catch(NumberFormatException e){
            LOG.info("Convertidor -------------- "+e);
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object ooj) {
        try{
           LOG.info("Convertidor "+ooj);
           Evento evento = (Evento)ooj;
           LOG.info("Convertidor "+evento);
           if(evento==null) {
                return null;
            }
           return evento.getEvCodigo().toString();
        }catch(Exception e){
            throw new UnsupportedOperationException("EventoConvertidor .- Error al convertir a String ");
        }
    }
    
}
